package cn.edu.tust.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.tust.model.UserInfoModel;
import cn.edu.tust.myUtils.MyUtils;

/**
 * ajax 删除操作
 */
@WebServlet("/UserInfoDeleteServlet")
public class UserInfoDeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// ajax修改查询
		// 设置request、response的编码，防止中文乱码
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		// 获取查询参数
		String strUserId = request.getParameter("uid");
		// 进行ajax响应处理
		// 调用model层进行数据库查询操作
		int ii = MyUtils.getNewInstance(UserInfoModel.class).deleteUserInfoByID(strUserId);
		// 根据操作的业务逻辑返回内容
		String strResult = "failed";
		if (ii > 0) {
			strResult = "deleted";
		}
		// 将查询结果返回给ajax引擎
		PrintWriter pw = response.getWriter();
		// 将返回的内容发送给客户端的ajax引擎
		pw.println(strResult);
	}

}
